export default function htmlPlugin(data) {
  return {
    name: 'vite:htmlPlugin',
    transformIndexHtml: {
      enforce: 'pre',
      transform(html, ctx) {
        const _html = renderHtml(html, data)
        return {
          html: _html,
          tags: []
        }
      }
    }
  }
}

function renderHtml(html, data) {
  Object.keys(data).forEach((key) => {
    html = html.replace(`<%= ${key} =%>`, data[key])
  })
  // console.log(html)
  return html
}
